// pages/toPlayList/toPlayList.js
var pageNum = 2;
var pageSize = 10;
const http = require('../../http/http')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    playList: [],
    listId: null,
    showSongRigon: true,
    showPlayer:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let playList = JSON.parse(decodeURIComponent(options.playList))
    console.log(playList)
    this.setData({
      playList: playList,
      listId: '',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      showSongRigon:false,
      showPlayer:false,
    })
    this.setData({
      showSongRigon:true,
      showPlayer:true,
  })
    pageNum = 2;
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.setData({ 
      show: false 
    }) 
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },
  refreshSongRigon(){
    this.setData({
      showSongRigon:false,
    })
    this.setData({
      showSongRigon:true,
  })
  },
  getSongList() {
    const res2 = http.getUserCollectionDetalis({
      playlistId: app.globalData.refreshListId,
      limit: pageNum * pageSize
    })
    pageNum = pageNum + 1;
    res2.then((data) => {
      console.log(data);
      this.setData({
        playList: data
      })
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    setTimeout(()=>{
        },1000)
        wx.showLoading({
      title:"刷新中"
        });
        setTimeout(()=>{
          wx.hideLoading()
        },1000)
    console.log("下拉刷新");
    pageNum=1;
    this.getSongList();
  },
  
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    setTimeout(() => {
      this.getSongList()
    }, 1000)

    wx.showLoading({
      title: "加载中"
    });
    setTimeout(() => {
      wx.hideLoading()
    }, 1000)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})